﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="com.vs.RF.Web.Main" EnableViewState="false" MasterPageFile="~/RF.Master" %>
<%@ Import Namespace="com.vs.DataAccess" %>
<%@ Import Namespace="System.Data" %>
<asp:Content ID="Content1" ContentPlaceHolderID="body" runat="server">

    <script language="javascript" type="text/javascript">
        <% 
            string stOption = null;
            string stLink = null;
            if (null != this.dtOptions && dtOptions.Rows.Count > 0)
            {
        %>
        var actions = new Array(<%= dtOptions.Rows.Count %>);
        <%
                for (int i=0; i<dtOptions.Rows.Count; i++){
                    stLink = DataManager.GetString(dtOptions.Rows[i], "VALUE");
        %>
        actions[<%= i %>] = "<%= stLink %>";
        <%
                }
            }
        %>
        
        var iNumOfSubmit = 0;
        function valForm() {
            if (form1.tbChoice.value == ""){
                alert("请选择功能");
                form1.tbChoice.focus();
                return false;
            }
            return true;    
        }
        
        function btnOK_Click() {
            if (iNumOfSubmit > 0)
                return;
                
            if (valForm()){
                var iChoice = form1.tbChoice.value;
                if (iChoice > <%= dtOptions.Rows.Count %>){
                    alert("选项不存在");
                    form1.tbChoice.focus();
                    return false;
                }
                else{
                    iNumOfSubmit++;
                    form1.hdTarget.value = actions[iChoice - 1];
                    form1.submit();
                }
            }
        }

        function btnCancel_Click() {
            form1.action = "Login.aspx";
            form1.submit();
        }
        
        function on_Load(){
            form1.tbChoice.focus();
        }
        
        function on_KeyDown(event){
            if(event.keyCode == "13")
                btnOK_Click();
        }
    </script>
    
    <%= stErrorMessage %>
    <form id="form1" action="MainHandling.aspx" method="post">
        <input type="hidden" name="hdTarget" />
    <div>    
        <table>
            <tr>
                <td>选择：</td>
                <td><input type="text" id="tbChoice" class="greyRed" onkeydown="on_KeyDown(event)" /></td>
            </tr>
            <%
                if (null != this.dtOptions && dtOptions.Rows.Count > 0)
                {
                    int iIdx = 0;
                    foreach (DataRow dr in dtOptions.Rows)
                    {
                        iIdx++;
                        stOption = DataManager.GetString(dr, "DESCRIPTION");
                        stLink = DataManager.GetString(dr, "VALUE"); 
            %>
            <tr>
                <td><%=iIdx%></td>
                <td><a href="javascript:form1.hdTarget.value='<%=stLink %>'; form1.submit();"><%=stOption%></a></td>
            </tr>
            <%
                    }
                }
            %>
        </table>
    </div>
    <div id="footer">  
        <input type="button" id="btnOK" value="确定" onclick="btnOK_Click()" class="greyRed"/>
        <input type="button" id="btnCancel" value="退出" onclick="btnCancel_Click()" class="greyRed" />
    </div>
    </form>
</asp:Content>
